package com.qk.management.JWTTests;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class jwttests {
    @Test
    public void testjwts(){
        Map<String, Object> claims = new HashMap<>();
        claims.put("name","张三");
        claims.put("age",18);
        String jbu = Jwts.builder().setId("1")
                .setClaims(claims)
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24))
                .signWith(SignatureAlgorithm.HS256, "qk11111111")
                .compact();
        System.out.println(jbu);
    }
    @Test
    public void testjwtp(){
        String jwt = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoi5byg5LiJIiwiZXhwIjoxNzYwMjM0OTg1LCJpYXQiOjE3NjAxNDg1ODUsImFnZSI6MTh9._PmxRr4sevj2RySBtmfyR0ZtMoyXKTv-wMG6Bqy0kBo";
        System.out.println(Jwts.parser().setSigningKey("qk11111111").parseClaimsJws(jwt));
    }
}
